package controller

import (
	"encoding/json"
	"github.com/gin-gonic/gin"
	"house-property/common"
	"house-property/model"
	"strconv"
)

func Standard(ctx *gin.Context){
	DB:=common.InitDB()
	b, _ := ctx.GetRawData()
	var m map[string]string
	_ = json.Unmarshal(b, &m)
	var sta []model.Housesta
	DB.Find(&sta)
	ctx.JSON(200,sta)
}
func Deletesta(ctx *gin.Context) {
	DB:=common.InitDB()
	 area:=ctx.Query("id");
	 if area!=""{
		 ctx.JSON(200, gin.H{
			 "code":200,
		 })
	 }
	 var sta model.Housesta
	 DB.Where("AREA = ?", area).Delete(&sta)
}
func Modifysta(ctx *gin.Context){
	DB := common.InitDB()
	b, _ := ctx.GetRawData()
	var m map[string]string
	_ = json.Unmarshal(b, &m)
	area2 := m["area"]
	score := m["score"]
	s,_:=strconv.Atoi(score)
	newsta2 := model.Housesta{
		Area:  area2,
		Score: s,
	}
	DB.Create(&newsta2)
	//返回结果
	ctx.JSON(200,gin.H{
		"code":200,
		"msg":newsta2,
	})
}
//func getdata(db *gorm.DB) []model.House_sta{
//	var sta []model.House_sta
//	db.Find(&sta)
//	return sta
//}


